package cn.jisol.ngame.sync.bridge;

import cn.jisol.ngame.ncall.NCallService;
import cn.jisol.ngame.sync.NSyncMode;
import cn.jisol.ngame.sync.NFPSInfo;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * 桥接同步(NGame 特殊同步)
 * 逻辑 连接一个Game服务端 收集消息 发送给所有客户端
 */
@Getter
@Setter
public class NSyncBridgeMode<D> implements NSyncMode {

    private NCallService nCallService;
    
    //数据列表
    private ArrayList<NFPSInfo<D>> dataList = new ArrayList<>();
    
    //最新状态
    private NFPSInfo<D> lastInfo = null;
    
    @Override
    public void init(NCallService nCallService) {
        this.nCallService = nCallService;
    }

    @Override
    public void start() {

    }

    @Override
    public void end() {

    }
    
    //获取指定开始到结束的帧
    public List<NFPSInfo<D>> vGetFrame(Integer start, Integer end){
        
        //默认值
        if(Objects.isNull(start)) start = 0;
        if(Objects.isNull(end)) end = this.dataList.size() - 1;
        
        return new CopyOnWriteArrayList<>(this.dataList.subList(start, end));
        
    }
    
    //将数据插入
    public void addFPSInfo(NFPSInfo<D> info){
        this.dataList.add(info.getI().intValue(),info);
    }
    
}
